#region Copyright
/// <copyright>
/// Copyright (c) 2007 Ilia Shramko.
/// Released under the terms of the GNU General Public License.
/// </copyright>
#endregion

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Osh.Media
{
	public class VideoFile : ProgramBase, IVideoFile
	{
		private IAudioStream _currentAudio;
		private IVideoStream _currentVideo;
		private ISubtitleStream _currentSubtitles;
		private AudioStreamCollection _audioStreams;
		private VideoStreamCollection _videoStreams;
		private SubtitleStreamCollection _subtitleStreams;

		public VideoFile()
		{
		}

		public VideoFile(IMediaLibrary library, Uri uri)
			: base(library, uri)
		{
			string fileName = Path.GetFileName(uri.LocalPath);
			this.FileName = fileName;
			this.Name = Path.GetFileNameWithoutExtension(fileName);
		}

		public override Uri Uri
		{
			get { return base.Uri; }
			protected set
			{
				base.Uri = value;
				
				string fileName = Path.GetFileName(value.LocalPath);
				this.FileName = fileName;
				this.Name = Path.GetFileNameWithoutExtension(fileName);
			}
		}

		public override string Name
		{
			get { return this.Attributes[MediaAttributeNames.FileNameWithoutExtension] as string; }
			protected set { this.Attributes[MediaAttributeNames.FileNameWithoutExtension] = value; }
		}

		#region IVideoFile
		public virtual string FileName
		{
			get { return this.Attributes[MediaAttributeNames.FileName] as string; }
			protected set { this.Attributes[MediaAttributeNames.FileName] = value; }
		}

		public virtual IAudioStream CurrentAudio
		{
			get { return _currentAudio; }
			protected set { _currentAudio = value; }
		}

		public virtual IVideoStream CurrentVideo
		{
			get { return _currentVideo; }
			protected set { _currentVideo = value; }
		}

		public virtual ISubtitleStream CurrentSubtitles
		{
			get { return _currentSubtitles; }
			protected set { _currentSubtitles = value; }
		}

		public virtual AudioStreamCollection AudioStreams
		{
			get
			{
				if(_audioStreams == null)
					_audioStreams = new AudioStreamCollection();
				return _audioStreams;
			}
			protected set { _audioStreams = value; }
		}

		public virtual VideoStreamCollection VideoStreams
		{
			get
			{
				if(_videoStreams == null)
					_videoStreams = new VideoStreamCollection();
				return _videoStreams;
			}
			protected set { _videoStreams = value; }
		}

		public virtual SubtitleStreamCollection SubtitleStreams
		{
			get
			{
				if(_subtitleStreams == null)
					_subtitleStreams = new SubtitleStreamCollection();
				return _subtitleStreams;
			}
			protected set { _subtitleStreams = value; }
		}
		#endregion IVideoFile
	}
}
